$(function () {
    var code = 9999;
    function codes() {

        var ranColor = '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6); //随机生成颜色
        // alert(ranColor)
        var ranColor2 = '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).slice(-6);
        var num1 = Math.floor(Math.random() * 100);
        var num2 = Math.floor(Math.random() * 100);
        code = num1 + num2;

        $("#code").html(num1 + "+" + num2 + "=?");
        if ($("#code").hasClass("nocode")) {
            $("#code").removeClass("nocode");
            $("#code").addClass("code");

        }
        $("#code").css('background', ranColor);
        $("#code").css('color', ranColor2);

    }
    codes();

    $("#code").on('click', codes)
    $("#check").click(function () {

        if ($(".input").val() == code && code != 9999) {
            $.ajax({
                url: "http://localhost:25744/api/User",
                type: "get",
                dataType: "json",
                data: { Users_Account: $("#zhang").val(), Users_Pwd: $("#mi").val() },
                success: function (str) {
                    if (str != null || str != "") {
                        var s1 = encodeURI(str.Users_Name);
                        location.href = '/Home/Index?uname=' + s1 + "," + str.Users_Id;
                    }
                    else {
                        alert("账号或密码错误")
                    }
                }
            })
        } else {
            alert("验证码错误!");
        }
    });
   
});
